package log

import (
	"github.com/pkg/errors"

	"github.com/sirupsen/logrus"
	kl "github.com/tracer0tong/kafkalogrus"
)

func NewKafkaHook(id string, formatter logrus.Formatter, brokers []string) error {
	kafkaHook, err := kl.NewKafkaLogrusHook(id, logrus.AllLevels, formatter, brokers, "KafkaInput", true, nil)
	if err != nil {
		logrus.Errorf("config es logger error. %+v", errors.WithStack(err))
		return err
	}

	logrus.AddHook(kafkaHook)
	return nil
}
